/*
 * @Description: 行程订单详情   ItineraryOrderDetails
 * @version: 
 * @Company: 
 * @Author: ZhengZhuang
 * @Date: 2019-08-30 15:33:08
 * @LastAuthor   : zhengzhuang
 * @lastTime     : 2019-12-30 17:36:20
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/config/service_api.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:url_launcher/url_launcher.dart';
// import 'package:C20Driver/provider/itinerary_order_provider.dart';
import 'package:C20Driver/service/service_method.dart';
import 'package:C20Driver/widget/spinkit.dart';

class ItineraryOrderDetails extends StatelessWidget {
  ItineraryOrderDetails({this.id});
  final String id;

  Future _getTripOrderInfo(context) async {
    return await DioUtils()
        .request(ReqMethod.POST, ServiceApi.getTripOrderInfo, params: {
      'order_id': id,
    }, success: (res) async {
      return res;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('行程详情')),
      body: FutureBuilder(
        future: _getTripOrderInfo(context),
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.hasData) {
            // var getTripOrderInfoData = GetTripOrderInfo.fromJson(snapshot.data);
            var getTripOrderInfoData = snapshot.data;
            return Container(
              padding: EdgeInsets.only(
                left: ScreenUtil().setWidth(25.0),
                right: ScreenUtil().setWidth(25.0),
              ),
              child: Column(
                children: <Widget>[
                  _itineraryOrderDetailsHead(getTripOrderInfoData),
                  _informationTrip(getTripOrderInfoData),
                  SizedBox(height: ScreenUtil().setHeight(100.0)),
                  Offstage(
                    offstage: getTripOrderInfoData['status'] != '0030',
                    child: MaterialButton(
                      color: Colors.blueAccent,
                      minWidth: ScreenUtil().setWidth(650.0),
                      height: ScreenUtil().setHeight(80.0),
                      child: Text(
                        '发起收款',
                        style: TextStyle(
                            fontSize: ScreenUtil().setSp(30.0),
                            color: Colors.white),
                      ),
                      onPressed: () {
                        NavigatorUtil.jump(context,
                            "/confirmedAmount?orderId=${getTripOrderInfoData['id']}&sumCost=${getTripOrderInfoData['sum_cost']}&startCost=${getTripOrderInfoData['start_cost']}&timeCost=${getTripOrderInfoData['time_cost']}&distanceCost=${getTripOrderInfoData['distance_cost']}");
                      },
                    ),
                  ),
                ],
              ),
            );
          } else {
            return Spinkit();
          }
        },
      ),
    );
  }

  // 行程人信息头部
  Widget _itineraryOrderDetailsHead(getTripOrderInfoData) {
    return Card(
      child: Container(
        padding: EdgeInsets.all(ScreenUtil().setWidth(25.0)),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Row(
              children: <Widget>[
                ClipOval(
                  child: Image.network(
                    // getTripOrderInfoData.passengerHeadimgurl,
                    getTripOrderInfoData['passenger_headimgurl'].toString(),
                    width: ScreenUtil().setWidth(80.0),
                    height: ScreenUtil().setWidth(80.0),
                    fit: BoxFit.cover,
                  ),
                ),
                SizedBox(
                  width: ScreenUtil().setWidth(10.0),
                ),
                Text(
                  // getTripOrderInfoData.passengerName,
                  getTripOrderInfoData['passenger_name'].toString(),
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(30.0),
                  ),
                ),
              ],
            ),
            Row(
              children: <Widget>[
                // IconButton(
                //   icon: Icon(Icons.chat),
                //   onPressed: () {},
                // ),
                IconButton(
                  icon: Icon(Icons.call),
                  onPressed: () async {
                    // var url = 'tel:${getTripOrderInfoData.passengerMobile}';
                    var url =
                        'tel:${getTripOrderInfoData['passenger_mobile'].toString()}';
                    if (await canLaunch(url)) {
                      await launch(url);
                    } else {
                      throw 'Could not launch $url';
                    }
                  },
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  // 本次行程信息
  Widget _informationTrip(getTripOrderInfoData) {
    return Container(
      width: ScreenUtil().setWidth(700.0),
      child: Card(
        child: Container(
          padding: EdgeInsets.all(ScreenUtil().setWidth(25.0)),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Icon(
                        Icons.access_time,
                        size: ScreenUtil().setWidth(16.0),
                        color: Color.fromARGB(255, 205, 205, 205),
                      ),
                      SizedBox(
                        width: ScreenUtil().setWidth(10.0),
                      ),
                      Text(
                        // getTripOrderInfoData.driveTime != null
                        //     ? getTripOrderInfoData.driveTime
                        //     : '',
                        getTripOrderInfoData['update_time'].toString(),
                        style: TextStyle(
                          fontSize: ScreenUtil().setSp(30.0),
                          color: Color.fromARGB(255, 102, 102, 102),
                        ),
                      ),
                    ],
                  ),
                  Offstage(
                    offstage:
                        !(getTripOrderInfoData['status'].toString() == '0030'),
                    child: Text(
                      '等待支付',
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(32.0),
                        color: Colors.orange,
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                  ),
                  Offstage(
                    offstage:
                        !(getTripOrderInfoData['status'].toString() == '0000'),
                    child: Text(
                      '支付成功',
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(32.0),
                        color: Colors.black,
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                  ),
                ],
              ),
              SizedBox(height: ScreenUtil().setWidth(15.0)),
              Row(
                children: <Widget>[
                  Container(
                    width: ScreenUtil().setWidth(15.0),
                    height: ScreenUtil().setWidth(15.0),
                    decoration: BoxDecoration(
                      color: Color.fromARGB(255, 36, 142, 247),
                      shape: BoxShape.circle,
                    ),
                  ),
                  SizedBox(width: ScreenUtil().setWidth(10.0)),
                  Container(
                    width: ScreenUtil().setWidth(600.0),
                    child: Text(
                      getTripOrderInfoData['dep_are'],
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(30.0),
                        color: Color.fromARGB(255, 102, 102, 102),
                      ),
                    ),
                  ),
                ],
              ),
              SizedBox(height: ScreenUtil().setWidth(15.0)),
              Row(
                children: <Widget>[
                  Container(
                    width: ScreenUtil().setWidth(15.0),
                    height: ScreenUtil().setWidth(15.0),
                    decoration: BoxDecoration(
                      color: Color.fromARGB(255, 255, 153, 0),
                      shape: BoxShape.circle,
                    ),
                  ),
                  SizedBox(width: ScreenUtil().setWidth(10.0)),
                  Container(
                    width: ScreenUtil().setWidth(600.0),
                    child: Text(
                      getTripOrderInfoData['dest_area'],
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(30.0),
                        color: Color.fromARGB(255, 102, 102, 102),
                      ),
                    ),
                  ),
                ],
              ),
              Divider(
                color: Colors.grey,
                height: 32.0, // 高度
              ), // 分隔符
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    '总费用',
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(30.0),
                      color: Colors.black54,
                    ),
                  ),
                  Text(
                    '￥${getTripOrderInfoData['sum_cost'].toString()}',
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(30.0),
                      color: Colors.black87,
                    ),
                  ),
                ],
              ),
              // SizedBox(
              //   height: ScreenUtil().setWidth(20.0),
              // ),
              // Row(
              //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
              //   children: <Widget>[
              //     Text(
              //       '时常费（10分钟）',
              //       style: TextStyle(
              //         fontSize: ScreenUtil().setSp(30.0),
              //         color: Colors.black54,
              //       ),
              //     ),
              //     Text(
              //       '￥3.50',
              //       style: TextStyle(
              //         fontSize: ScreenUtil().setSp(30.0),
              //         color: Colors.black87,
              //       ),
              //     ),
              //   ],
              // ),
              // SizedBox(
              //   height: ScreenUtil().setWidth(20.0),
              // ),
              // Row(
              //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
              //   children: <Widget>[
              //     Text(
              //       '等待费（10分钟）',
              //       style: TextStyle(
              //         fontSize: ScreenUtil().setSp(30.0),
              //         color: Colors.black54,
              //       ),
              //     ),
              //     Text(
              //       '￥3.50',
              //       style: TextStyle(
              //         fontSize: ScreenUtil().setSp(30.0),
              //         color: Colors.black87,
              //       ),
              //     ),
              //   ],
              // ),
              // SizedBox(
              //   height: ScreenUtil().setWidth(30.0),
              // ),
            ],
          ),
        ),
      ),
    );
  }
}
